<?php

namespace App\Model;

use Illuminate\Database\Eloquent\Model;

class Store_station extends Model
{
    //
	protected $table='store_station';
	protected $fillable=[
		'id','station_id','store_id','name','num','status','start_time','end_time','company_id','department_id','comment'
	];
	protected $hidden;

//	查询该店铺下所有的岗位
	public function allStations($store_id){
		 $data=$this->where(['store_id'=>$store_id])->where('status' ,'!=','-1')->with('station')
			 ->get();

		foreach ($data as $kk=>$vv){
			$data[$kk]['statu']=$vv['status']==1?'长期有效':'短期有效';
			$data[$kk]['station']['status']=$vv['station']['status']==1?'有效':'无效';
		}
		return $data;
	}

//	查询该店铺下所有的岗位
	public function allStations_($store_id){
		$data=$this->where(['store_id'=>$store_id])->where('status' ,'!=','-1')->with('station')
			->with('period_status')->paginate(config('app.config'));
		return $data;
	}
//	查询该店铺下所有的岗位接口
	public function allStations__($department_id){
		$data=$this->where(['department_id'=>$department_id])->where('status' ,'=','1')->select('id','name')->get();
		return $data;
	}


//	public function allStations__($department_id){
//		$storeData=Store::where(['department_id'=>$department_id])->first();
//		if(count($storeData)){
//			$store_id=$storeData->id;
//			$data=$this->where(['store_id'=>$store_id])->where('status' ,'=','1')->with('station')
//				->with('period_status')->get();
//		}else{
//			$data=[];
//		}
//		return $data;
//	}

//	查询店铺岗位的详细信息
	public function store_station_desc($id){
		return $this->where(['id'=>$id])->with('station')->first();
	}

//	岗位详情
	public function station(){
		return $this->belongsTo('App\Model\Station','station_id');
	}

	public function period_status(){
		return $this->belongsTo('App\Model\Period_status','status','period_id');
	}


//	获取所有非门店人员列表
	public function no_store_station($where){
		$data=$this->where(['department_id'=>$where['department_id'],'company_id'=>$where['company_id']])
			->whereNull('store_id')->with('station')->get();
		return $data;
	}
}
